package com.litorg.demo.db.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.litorg.demo.db.config.SendRedisMsg;
import com.litorg.demo.db.mapper.TestMapper;
import com.litorg.demo.db.mapper.UserMapper;
import com.litorg.demo.db.service.TestService;
import com.litorg.demo.db.vo.BusinessData;
import com.litorg.demo.db.vo.TestVO;
import com.litorg.demo.db.vo.User;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * @Despriction:
 * @Author: wangcheng
 * @Date: 2023/1/4 15:35
 */
@Service
public class TestServiceImpl implements TestService {
	private static final Logger log = LoggerFactory.getLogger(TestServiceImpl.class);

	@Autowired
	private UserMapper userMapper;

	@Async("testTaskExecutor")
	@Override
	public CompletableFuture<String> test(String msg) {
		log.info("--------------------------: {}", msg);
		return CompletableFuture.completedFuture(msg);
	}

	@SendRedisMsg(topic = "abc", subtype = "#datas[0].id", stationId = "dasd")
	@Override
	public JSONObject sayHello(List<BusinessData> datas) {
		log.info("hello ,{}", JSON.toJSONString(datas));
		return JSONObject.parseObject(JSON.toJSONString(datas.get(0)));
	}

	@Override
	public int save(User user) {
		return userMapper.insert(user);
	}
}
